import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/Home/home.vue'
import ProjectView from '../views/Project/index.vue'
import WelcomeView from '../views/Work/Welcome.vue'
import JobView from '../views/Work/JobView.vue'
import FileView from '../views/TeamWork/FileView.vue'
import DownloadView from '../views/TeamWork/DownloadView.vue'
import RegisterView from '../views/Login/Register.vue'
import TestView from '../views/TestDemo/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login/login.vue')
  },
  {
    path: '/home',
    component: HomeView,
    redirect: '/work',
    children: [

      // 工作管理
      {path: '/work',redirect: '/work/welcom'},
      {path: '/work/welcom',component: WelcomeView,name:'welcome'},
      {path: '/work/job',component: JobView,name:'job'},
      {path: '/work/kaoqin',component: WelcomeView,name:'welcome'},
      {path: '/work/news',component: WelcomeView,name:'welcome'},

      {path: '/project',component: ProjectView,name:'project'},
      {path: '/email',component: ProjectView,name:'project'},

      {path: '/teamwork',redirect: '/teamwork/files'},
      {path: '/teamwork/files',component: FileView,name:'files'},
      {path: '/teamwork/downloads',component: DownloadView,name:'downloads'},
      
      {path: '/schedule',redirect: '/schedule/day'},
      {path: '/schedule/day',component: ProjectView,name:'day'},
      {path: '/schedule/week',component: ProjectView,name:'week'},
      {path: '/schedule/month',component: ProjectView,name:'month'},
      {path: '/schedule/year',component: ProjectView,name:'year'},
      
      {path: '/meeting',component: ProjectView,name:'project'},
      {path: '/addressbook',component: ProjectView,name:'project'},
      {path: '/system',component: ProjectView,name:'project'},
      {path: '/test',component: TestView,name:'test'},
    ]
  },
  {
    path:'/Register',
    name:'Register',
    component: RegisterView
  },
  {
    path:'/getPsd',
    name:'getPsd',
    component: () => import('../views/Login/getPsd.vue')
  }
  
]

const router = new VueRouter({
  routes
})

/* // 挂载路由导航守卫，只有登录通过才能进入，否则重定向到login页面
router.beforeEach((to, from, next) => {
  //to 将要访问的路径
  //from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  // 两种方式： next() 直接放行  ； next('/login') 强制跳转
  if (to.path === "/login") return next();
  // 获取 token
  const tokenStr = window.sessionStorage.getItem("token");
  if (!tokenStr) return next("/login");
  next();
}) */

export default router
